package com.wd.buycar.view.activity

import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.ToastUtils
import com.bumptech.glide.Glide
import com.wd.buycar.databinding.ActivityNewCarDetailsBinding
import com.wd.common.DataHelper
import com.wd.common.base.BaseActivity
import com.wd.common.viewmodel.MyViewModel

class NewCarDetailsActivity : BaseActivity<ActivityNewCarDetailsBinding, Any?>() {
    val viewmodel: MyViewModel by viewModels()
    override fun getViewBinding(): ActivityNewCarDetailsBinding =
        ActivityNewCarDetailsBinding.inflate(layoutInflater)

    override fun initData() {
        val id = this.intent.getIntExtra("id", 0)
        val name = this.intent.getStringExtra("name")

        viewmodel.buy_newcarDetails(id)
        viewmodel.buy_newcarDetailsLiveData.observe(this, Observer {
            binding.buyNewcarDetailstext.setText(it.result.name)
            binding.buyNewcarDetailsView3Text1.setText(it.result.name)
            binding.buyNewcarDetailsView4Text1.setText(it.result.name)
            binding.buyNewcarDetailsView5Text1.setText(it.result.name)
            binding.buyNewcarDetailsPrice.setText(it.result.lowestClosingCost+"万")
            Glide.with(this)
                .load(it.result.bgImageUrl)
                .into(binding.buyNewcarDetailsImage)
        })
        //外观
        binding.buyNewcarDetailsSurface1.setOnClickListener {
            val intent = Intent(this, NewCarWaiActivity::class.java)
            intent.putExtra("wainame", name)
            intent.putExtra("id", id)
            startActivity(intent)
        }
        //内饰
        binding.buyNewcarDetailsSurface2.setOnClickListener {
            val intent = Intent(this, NewCarNeiActivity::class.java)
            intent.putExtra("neiname", name)
            intent.putExtra("id", id)
            startActivity(intent)
        }
        //VR看车
        binding.buyNewcarDetailsSurface4.setOnClickListener {
            val intent = Intent(this, CarViewActivity::class.java)
            intent.putExtra("id", id)
            startActivity(intent)
        }

        binding.buyNewcarDetailstext.setOnClickListener {
            finish()
        }

    }

    fun addContrast(view: View) {
        val id = intent.getIntExtra("id", 0)
        for(a in DataHelper.list){
            if(a == id){
                ToastUtils.showShort("当前车辆已经添加过了")
                return
            }
        }
        DataHelper.list.add(id)
        ToastUtils.showShort("添加成功")
    }
}